package csci5115.autoalarm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.ExpandableListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
import android.view.ViewGroup;

public class SettingsTabActivity extends ExpandableListActivity {
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        
        final String NAME = "name";
        final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();

        final HashMap<String, String> group1 = new HashMap<String, String>();
        group1.put(NAME, "Google Account");
        headerData.add( group1 );

        final HashMap<String, String> group2 = new HashMap<String, String>();
        group2.put(NAME, "Sync Settings");
        headerData.add( group2);


        final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();

        final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
        childData.add(group1data);

        final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>();
        childData.add(group2data);


        // Set up some sample data in both groups
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put(NAME, "john.doe@gmail.com");
        group1data.add(map);
        map = new HashMap<String, Object>();
        map.put(NAME, "Sync different account...");
        group1data.add(map);
        
        map = new HashMap<String, Object>();
        map.put(NAME, "Sync events for the next: 3 weeks");
        group2data.add(map);
        map = new HashMap<String, Object>();
        map.put(NAME, "Sync events for the previous: 1 week");
        group2data.add(map);
        map = new HashMap<String, Object>();
        map.put(NAME, "Sync every: 5 minutes");
        group2data.add(map);

        setListAdapter( new SimpleExpandableListAdapter(
                this,
                headerData,
                android.R.layout.simple_expandable_list_item_1,
                new String[] { NAME },            // the name of the field data
                new int[] { android.R.id.text1 }, // the text field to populate with the field data
                childData,
                0,
                null,
                new int[] {}
            ) {
                @SuppressWarnings("unchecked")
				@Override
                public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
                    final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);

                    // Populate your custom view here
                    ((TextView)v.findViewById(
                    		R.id.name)).setText(
                    				(String) ((Map<String,Object>)getChild(
                    						groupPosition, childPosition)).get(
                    								NAME)
                    						);
//                    ((ImageView)v.findViewById(R.id.image)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(IMAGE) );

                    return v;
                }

                @Override
                public View newChildView(boolean isLastChild, ViewGroup parent) {
                     return layoutInflater.inflate(R.layout.expandable_list_item_with_image, null, false);
                }
            }
        );
        
	}
}
